//
//  HousingViewController.swift
//  Swift训练
//
//  Created by zhenjingxiong on 2018/8/30.
//  Copyright © 2018年 zhenjingxiong. All rights reserved.
//

import UIKit

class HousingViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.layoutUI()
        
    }
    
    
    func layoutUI() {
        
        self.navigationItem.rightBarButtonItem = UIBarButtonItem.init(image: UIImage.init(named: "icon_refresh"), style: UIBarButtonItemStyle.done, target: self, action: #selector(refresh))
        
        self.view.addSubview(self.topView)
        
        self.topView.addSubview(self.firstView)
        
        let tapFirstView = UITapGestureRecognizer.init(target: self, action: #selector(clickFirst))
        self.firstView.addGestureRecognizer(tapFirstView)
        
        self.topView.addSubview(self.sencondView)
        let tapSecondView = UITapGestureRecognizer.init(target: self, action: #selector(clickSecond))
        self.sencondView.addGestureRecognizer(tapSecondView)
        
        self.firstView.addSubview(self.pinControlLabel)
        self.pinControlLabel.snp.makeConstraints { (make) in
            make.center.equalTo(self.firstView)
        }
        
        self.sencondView.addSubview(self.intentionLabel)
        self.intentionLabel.snp.makeConstraints { (make) in
            make.center.equalTo(self.sencondView)
        }
        
        //添加下划线
        self.topView.addSubview(self.underlineImageView)
        
        self.view.addSubview(self.leftListView)
        self.leftListView.snp.makeConstraints { (make) in
            make.left.bottom.equalTo(self.view)
            make.width.equalTo(50)
            make.top.equalTo(self.underlineImageView.snp.bottom)
        }
        
        self.leftListView.register(UITableViewCell.self, forCellReuseIdentifier: "leftTabeleView")
        self.rightListView.register(UITableViewCell.self, forCellReuseIdentifier: "rightTabeleView")
        
        self.view.addSubview(self.rightScrollView)
        self.rightScrollView.snp.makeConstraints { (make) in
            make.left.equalTo(self.leftListView.snp.right)
            make.bottom.right.equalTo(self.view)
            make.top.equalTo(self.leftListView)
        }
        
        self.view.layoutIfNeeded()
        

        self.rightScrollView.addSubview(self.rightListView)
        self.rightListView.snp.makeConstraints { (make) in
            make.edges.equalTo(self.rightScrollView)
            make.width.equalTo(500)
            make.height.equalTo(504)
        }
  
}
    
    lazy var topView: UIView = {
        let topView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth, height: 50))
        return topView
    }()
    
    lazy var firstView: UIView = {
        let firstView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: ScreenWidth/2, height: 50))
        firstView.backgroundColor = UIColor.white
        return firstView
    }()
    
    lazy var sencondView: UIView = {
        let sencondView = UIView.init(frame: CGRect.init(x: ScreenWidth/2, y: 0, width: ScreenWidth/2, height: 50))
        sencondView.backgroundColor = UIColor.white
        return sencondView
    }()
    
    lazy var pinControlLabel: UILabel = {
        let pinControlLabel = UILabel.init()
        pinControlLabel.text = "销控"
        return pinControlLabel
    }()
    
    lazy var intentionLabel: UILabel = {
        let intentionLabel = UILabel.init()
        intentionLabel.text = "意向落位"
        return intentionLabel
    }()
    
    lazy var underlineImageView: UIImageView = {
        let underlineImageView = UIImageView.init(frame: CGRect.init(x: 0, y: 49, width: ScreenWidth/2, height: 1))
        underlineImageView.backgroundColor = UIColor.red
        return underlineImageView
    }()
    
    @objc func clickFirst()  {
        self.underlineImageView.frame = CGRect.init(x: 0, y: 49, width: ScreenWidth/2, height: 1)
    }
    
    @objc func clickSecond() {
        self.underlineImageView.frame = CGRect.init(x: ScreenWidth/2, y: 49, width: ScreenWidth/2, height: 1)
    }
    
    @objc func refresh() {
        
        print("刷新一下")
    }
    
    lazy var leftListView: UITableView = {
        let leftListView = UITableView.init()
        leftListView.backgroundColor = UIColor.yellow
        leftListView.delegate = self
        leftListView.dataSource = self
        return leftListView
    }()
    
    lazy var rightListView: UITableView = {
        let rightListView = UITableView.init()
//        let rightListView = UITableView.init(frame: CGRect.init(x: 0, y: 0, width: 500, height: 667))
        rightListView.backgroundColor = UIColor.blue
        rightListView.delegate = self
        rightListView.dataSource = self
        rightListView.bounces = false
        return rightListView
    }()
    
 
    
    lazy var rightScrollView: UIScrollView = {
        let rightScrollView = UIScrollView.init()
        rightScrollView.backgroundColor = UIColor.black
        rightScrollView.delegate = self
        rightScrollView.bounces = false
        return rightScrollView
    }()
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
       return 20
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if tableView == self.leftListView {
            let cell = tableView.dequeueReusableCell(withIdentifier: "leftTabeleView")
            cell?.textLabel?.text = "\(indexPath.row)"
            return cell!
        }else{
            let cell = tableView.dequeueReusableCell(withIdentifier: "rightTabeleView")
            cell?.textLabel?.text = "\(indexPath.row + 12333333333333)"
            return cell!
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    
    var i:Int = 0;
    
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        
        if scrollView == self.leftListView {
            self.rightListView.contentOffset = self.leftListView.contentOffset;
        }else{
            self.leftListView.contentOffset = self.rightListView.contentOffset;
//            print("%@",scrollView)
            i = i + 1;
            print("打印出来的数值是%d",i);
        }
        
    }

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
